package com.tbit.main.pojo;

import com.tbit.main.exception.BaseException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 运营数据查询传输实体类
 *
 * @Author:BUGTian
 * @DATE: 2022/11/1
 */
@Slf4j
@Data
@AllArgsConstructor
public class OperationalDataDTO implements Serializable {

    /**
     * 开始时间
     */
    private Date startTime;
    /**
     * 结束时间
     */
    private Date endTime;
    /**
     * 区域id 多个用,隔开
     */
    private String accountIds;

    /**
     * 品牌id
     */
    private Integer brandId;

    /**
     * 获取区域id List
     *
     * @return
     */
    public List<Integer> getAccountIdList() {
        List<Integer> accountIdList = new ArrayList<>();
        if (!StringUtils.hasText(accountIds)) {
            return accountIdList;
        }
        try {
            String[] accountIds = this.accountIds.split(",");
            for (String accountId : accountIds) {
                accountIdList.add(Integer.parseInt(accountId));
            }
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            throw new BaseException("区域id有误");
        }

        return accountIdList;
    }
}
